﻿// ////////////////////////////////////////////////////////////////////////////
// 
// SWE Case Tool
// 
// Solution:	CaseTool
// Project:		5. CaseToolUnitTests
// Filename:	PercentageMethod.cs
// 
// File Created:	15:43 31.05.2013 
// Last Changed:	18:10 05.06.2013
// 
// ////////////////////////////////////////////////////////////////////////////

using System;
using NUnit.Framework;
using SWE.CaseTool.Methods;
using Percentage = SWE.CaseTool.Methods.PercentageMethod;

namespace CaseToolUnitTests
{
	/// <summary>
	/// Unit tests for the percentage method. Reaches 100% of the calculation paths.
	/// </summary>
	[TestFixture]
	public class PercentageMethod
	{
		/// <summary>
		/// Tests the calculate method percentage with a given value for the definition phase.
		/// </summary>
		[Test]
		public void T001_PercentageNewDefinitionValue()
		{
			Assert.AreEqual(120, new Percentage
				{
					PartDefinition = 0.25,
					Phase = PercentagePhase.Definition,
					DurationReferencePhase = 30
				}.Calculate());
		}

		/// <summary>
		/// Tests the calculate method percentage with a given value for the concept phase.
		/// </summary>
		[Test]
		public void T002_PercentageNewDesignValue()
		{
			Assert.AreEqual(150, new Percentage
				{
					PartConcept = 0.20,
					Phase = PercentagePhase.Concept,
					DurationReferencePhase = 30
				}.Calculate());
		}

		/// <summary>
		/// Tests the calculate method percentage with a given value for the coding phase.
		/// </summary>
		[Test]
		public void T003_PercentageNewImplementationValue()
		{
			Assert.AreEqual(300, new Percentage
				{
					Phase = PercentagePhase.Coding,
					PartCoding = 0.10,
					DurationReferencePhase = 30
				}.Calculate());
		}

		/// <summary>
		/// Tests the calculate method percentage with a given value for the testing phase.
		/// </summary>
		[Test]
		public void T004_PercentageNewTestingValue()
		{
			Assert.AreEqual(100, new Percentage
				{
					PartTesting = 0.35,
					Phase = PercentagePhase.Testing,
					DurationReferencePhase = 35
				}.Calculate());
		}

		/// <summary>
		/// Tests the calculate method percentage without reference project.
		/// If the reference part concept has got the value 0 percentage the method has to throw a exception.
		/// </summary>
		[Test, ExpectedException(typeof (ArgumentException))]
		public void T006_PercentageNewNoPercentageDefinitionValue0()
		{
			new Percentage
				{
					PartConcept = 0,
					Phase = PercentagePhase.Concept
				}.Calculate();
		}

		/// <summary>
		/// Tests the calculate method percentage without reference project.
		/// If the reference part definition has got the value 0 percentage the method has to throw a exception.
		/// </summary>
		[Test, ExpectedException(typeof (ArgumentException))]
		public void T007_PercentageNewNoPercentageDesignValue0()
		{
			new Percentage
				{
					PartDefinition = 0,
					Phase = PercentagePhase.Definition
				}.Calculate();
		}

		/// <summary>
		/// Tests the calculate method percentage without reference project.
		/// If the reference part coding has got the value 0 percentage the method has to throw a exception.
		/// </summary>
		[Test, ExpectedException(typeof (ArgumentException))]
		public void T008_PercentageNewNoPercentageImplementationValue0()
		{
			new Percentage
				{
					PartCoding = 0,
					Phase = PercentagePhase.Coding
				}.Calculate();
		}

		/// <summary>
		/// Tests the calculate method percentage without reference project.
		/// If the reference part testing has got the value 0 percentage the method has to throw a exception.
		/// </summary>
		[Test, ExpectedException(typeof (ArgumentException))]
		public void T009_PercentageNewNoPercentageTestingValue0()
		{
			new Percentage
				{
					PartTesting = 0,
					Phase = PercentagePhase.Testing
				}.Calculate();
		}

		/// <summary>
		/// Tests the calculate method percentage without reference project.
		/// If the reference part concept has got a value greater than 100 percentage the method has to throw a
		/// exception.
		/// </summary>
		[Test, ExpectedException(typeof (ArgumentException)), Category("Percentage")]
		public void T010_PercentageNewNoPercentageDefinitionValueOver1()
		{
			new Percentage
				{
					PartConcept = 2,
					Phase = PercentagePhase.Concept
				}.Calculate();
		}

		/// <summary>
		/// Tests the calculate method percentage without reference project.
		/// If the reference part definition has got a value greater than 100 percentage the method has to throw
		/// a exception.
		/// </summary>
		[Test, ExpectedException(typeof (ArgumentException)), Category("Percentage")]
		public void T011_PercentageNewNoPercentageDesignValueOver1()
		{
			new Percentage
				{
					PartDefinition = 1.5,
					Phase = PercentagePhase.Definition
				}.Calculate();
		}

		/// <summary>
		/// Tests the calculate method percentage without reference project.
		/// If the reference part coding has got a value greater than 100 percentage the method has to throw a
		/// exception.
		/// </summary>
		[Test, ExpectedException(typeof (ArgumentException)), Category("Percentage")]
		public void T012_PercentageNewNoPercentageImplementationValueOver1()
		{
			new Percentage
				{
					PartCoding = 3,
					Phase = PercentagePhase.Coding
				}.Calculate();
		}

		/// <summary>
		/// Tests the calculate method percentage without reference project.
		/// If the reference part testing has got a value greater than 100 percentage the method has to throw a
		/// exception.
		/// </summary>
		[Test, ExpectedException(typeof (ArgumentException)), Category("Percentage")]
		public void T013_PercentageNewNoPercentageTestingValueOver1()
		{
			new Percentage
				{
					PartTesting = 1.5,
					Phase = PercentagePhase.Testing
				}.Calculate();
		}

		/// <summary>
		/// Tests the calculate method percentage with reference project.
		/// The test contains regular values for definition as reference phase.
		/// </summary>
		[Test]
		public void T014_PercentageDefinition()
		{
			Assert.AreEqual(125, new Percentage
				{
					Phase = PercentagePhase.Definition,
					UseReferenceProject = true,
					DurationReferencePhase = 25,
					PartRefDefinition = 0.20
				}.Calculate());
		}

		/// <summary>
		/// Tests the calculate method percentage with reference project.
		/// The test contains regular values for concept as reference phase.
		/// </summary>
		[Test]
		public void T015_PercentageDesign()
		{
			Assert.AreEqual(100, new Percentage
				{
					Phase = PercentagePhase.Concept,
					UseReferenceProject = true,
					PartRefConcept = 0.20,
					DurationReferencePhase = 20
				}.Calculate());
		}

		/// <summary>
		/// Tests the calculate method percentage with reference project.
		/// The test contains regular values for coding as reference phase.
		/// </summary>
		[Test]
		public void T016_PercentageImplementierung()
		{
			Assert.AreEqual(125, new Percentage
				{
					Phase = PercentagePhase.Coding,
					UseReferenceProject = true,
					PartCoding = 0.20,
					DurationReferencePhase = 25
				}.Calculate());
		}

		/// <summary>
		/// Tests the calculate method percentage with reference project.
		/// The test contains regular values for testing as reference phase.
		/// </summary>
		[Test]
		public void T017_PercentageTesting()
		{
			Assert.AreEqual(125, new Percentage
				{
					Phase = PercentagePhase.Testing,
					UseReferenceProject = true,
					PartTesting = 0.20,
					DurationReferencePhase = 25
				}.Calculate());
		}

		/// <summary>
		/// Tests the calculate method percentage with reference project.
		/// If the method has got the percentage value 0 it has to throw a exception.
		/// </summary>
		[Test, ExpectedException(typeof (ArgumentException))]
		public void T019_PercentageNoPerecentageValueDefinition()
		{
			new Percentage
				{
					Phase = PercentagePhase.Definition,
					UseReferenceProject = true,
					PartDefinition = 0,
					DurationReferencePhase = 30
				}.Calculate();
		}

		/// <summary>
		/// Tests the calculate method percentage with reference project.
		/// If the method has got the percentage value over 100 percentage it has to throw a exception.
		/// </summary>
		[Test, ExpectedException(typeof (ArgumentException))]
		public void T020_PercentageValueOver1Definition()
		{
			new Percentage
				{
					Phase = PercentagePhase.Definition,
					UseReferenceProject = true,
					PartDefinition = 2,
					DurationReferencePhase = 30
				}.Calculate();
		}
	}
}